package com.kxf.recyclerviewtest;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.squareup.picasso.Picasso;

import java.util.List;

public class GlideAdapter extends RecyclerView.Adapter<GlideAdapter.MyViewHolder> {
    private List<String> list;
    private Context context;
    private List<String> listImg;


    public GlideAdapter(Context context, List<String> list, List<String> listImg) {
        this.list = list;
        this.context = context;
        this.listImg = listImg;
    }

    @NonNull
    @Override
    public GlideAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fruit_item,parent,false);
        GlideAdapter.MyViewHolder holder = new GlideAdapter.MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull GlideAdapter.MyViewHolder holder, int position) {
        holder.textView.setText(list.get(position));
//        holder.textView.setHeight(300/(position%8+1));
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            holder.iv.setImageDrawable(context.getDrawable(R.drawable.ic_launcher_background));
//        }
//        Log.d("MyAdapter", "====" + listImg.size());
//        Glide.with(context).load(listImg.get(position%listImg.size())).into(holder.iv);
    }

    @Override
    public int getItemCount() {
//        Log.d("MyAdapter", "" + list.size());
        return list.size();
    }

    //内部类，绑定控件
    static class MyViewHolder extends RecyclerView.ViewHolder{
        TextView textView;
        ImageView iv;
        public MyViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.text_view);
            iv = itemView.findViewById(R.id.iv);
        }
    }
}

